package com.yaoxuguang.concurrence.simpleDataFormate_thread_question;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.simpleDataFormate_thread_question
 * @Description: SimpleDataFormat多线程下的并发问题
 * @date 2018年12月26日14:19
 */
public class MyThread extends Thread {
    private SimpleDateFormat simpleDateFormat;
    private String dateString;

    public MyThread(SimpleDateFormat simpleDateFormat, String dateString) {
        this.simpleDateFormat = simpleDateFormat;
        this.dateString = dateString;
    }

    /*@Override
    public void run() {
        try {
            Date date = simpleDateFormat.parse(dateString);
            String newDateString = simpleDateFormat.format(date);
            if(!newDateString.equals(dateString)){
                System.out.println("ThreadName="+this.getName()+
                        "异常，日期字符串："+dateString+"转换成的日期为："+newDateString);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }*/
    @Override
    public void run() {
        try {
            Date date = DateTools.getSimpleDateFormat("yyyy-MM-dd").parse(dateString);
            String newDateString = DateTools.getSimpleDateFormat("yyyy-MM-dd").format(date);
            if (!newDateString.equals(dateString)) {
                System.out.println("ThreadName=" + this.getName() +
                        "异常，日期字符串：" + dateString + "转换成的日期为：" + newDateString);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
